package swt.servic;

import swt.util.StringUtil;

public class SaleServic {
	public String getWhere(String starttime, String endtime, String compname,
			String trname, String penum, String address, String mintotal, String maxtotal){
		
		StringBuilder sb = new StringBuilder();
		String where="";
		sb.append("where ");
		if (!StringUtil.isEmpty(compname)) {
			sb.append("compname = '").append(compname).append("' and ");
		}
		if (!StringUtil.isEmpty(trname)) {
			sb.append("trname = '").append(trname).append("' and ");
		}
		if (!StringUtil.isEmpty(address)) {
			sb.append("`address` = '").append(address).append("' and ");
		}
		if (!StringUtil.isEmpty(penum)) {
			sb.append("penum = ").append(penum).append(" and ");
		}
		if (!StringUtil.isEmpty(starttime)) {
			sb.append("time >'").append(starttime).append("' and ");
		}
		if (!StringUtil.isEmpty(endtime)) {
			sb.append("time <'").append(endtime).append("' and ");
		}
		if (!StringUtil.isEmpty(mintotal)) {
			sb.append("totalmoney  >").append(mintotal).append(" and ");
		}
		if (!StringUtil.isEmpty(maxtotal)) {
			sb.append("totalmoney <").append(maxtotal);
		}

		if (sb.lastIndexOf("where ") != -1) {
			where = "";
		}
		System.out.println(sb.toString());
		where = sb.toString();
		if (where.endsWith("and ")) {
			where = where.substring(0, sb.lastIndexOf("and ")).toString();
		}
		return where;
	}
}
